package com.qiange.manager.service.impl;

import com.qiange.manager.Student.Student;
import com.qiange.manager.dao.IStudentDao;
import com.qiange.manager.dao.impl.StudentDaoImpl;
import com.qiange.manager.service.IStudentService;

import java.util.ArrayList;

public class StudentServiceImpl implements IStudentService {

    private IStudentDao studentDao = new StudentDaoImpl();
    @Override
    public boolean add(Student student) {
        return studentDao.add(student);
    }

    @Override
    public ArrayList<Student> findAll() {
        return studentDao.findAll();
    }

    @Override
    public boolean remove(int index) {
        return studentDao.remove(index);
    }

    @Override
    public boolean set(int index, Student student) {
        return studentDao.set(index,student);
    }

    @Override
    public int getIndexById(String sid) {
        ArrayList<Student> list = studentDao.findAll();
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if (sid.equals(student.getSid())){
                return i;
            }
        }
        return -1;
    }
}
